package com.carleasoft.mps.cms.business.train.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.train.bean.entity.*;
import com.carleasoft.mps.cms.business.train.bean.po.*;
import com.carleasoft.mps.cms.business.train.bean.vo.TrainPlanDetailVo;
import com.carleasoft.mps.cms.business.train.bean.vo.TrainPlanVo;
import com.carleasoft.mps.cms.business.train.service.TrainPlanService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 训练计划
 * </p>
 *
 * @author fan
 * @since 2023-05-17
 */
@RestController
@RequestMapping("/trainPlan")
public class TrainPlanController {

    @Autowired
    private TrainPlanService trainPlanService;

    /**
     * 训练计划-增加
     */
    @PostMapping("/trainPlanAdd")
    public R add(@RequestBody TrainPlanAddOrEditPo trainPlanAddOrEditPo){
        return R.ok(trainPlanService.add(trainPlanAddOrEditPo));
    }
    /**
     * 训练计划-编辑
     */
    @PostMapping("/trainPlanEdit")
    public R edit(@RequestBody TrainPlanAddOrEditPo trainPlanAddOrEditPo){
        return R.ok(trainPlanService.edit(trainPlanAddOrEditPo));
    }
    /**
     * 训练计划-删除
     */
    @PostMapping("/trainPlanDelete")
    public R delete(@RequestBody TrainPlan trainPlan){
        return R.ok(trainPlanService.delete(trainPlan));
    }
    /**
     * 训练计划-分页查询
     */
    @PostMapping("/trainPlanPageQuery")
    public R<Page<TrainPlanVo>> pageQuery(@RequestBody TrainPlanPageQueryPo trainPlanPageQueryPo){
        return R.ok(trainPlanService.pageQuery(trainPlanPageQueryPo));
    }
    /**
     * 训练计划-分页查询(门户不需要token)
     */
    @PostMapping("/door/trainPlanPageQuery")
    public R<Page<TrainPlanVo>> doorPageQuery(@RequestBody TrainPlanPageQueryPo trainPlanPageQueryPo){
        return R.ok(trainPlanService.doorPageQuery(trainPlanPageQueryPo));
    }
    /**
     * 训练计划-列表（条件查询）
     */
    @PostMapping("/trainPlanListByParam")
    public R<List<TrainPlan>> trainPlanListByParam(@RequestBody TrainPlan trainPlan){
        QueryWrapper<TrainPlan> queryWrapper = new QueryWrapper<TrainPlan>().eq("STATUS", 2).orderByDesc("CREATE_TIME");
        if (trainPlan.getTrainType()!=null){
            queryWrapper.eq("TRAIN_TYPE",trainPlan.getTrainType());
        }
        return R.ok(trainPlanService.list(queryWrapper));
    }
    /**
     * 训练计划-列表（下拉选择使用）
     */
    @PostMapping("/trainPlanList")
    public R<List<TrainPlanVo>> trainPlanList(){
        return R.ok(trainPlanService.trainPlanList());
    }

    /**
     * 训练计划-详情
     */
    @PostMapping("/trainPlanDetail")
    public R<TrainPlanDetailVo> detail(@RequestBody TrainPlan trainPlan){
        return R.ok(trainPlanService.detail(trainPlan));
    }
    /**
     * 训练计划-详情(不用token)
     */
    @PostMapping("/door/trainPlanDetail")
    public R<TrainPlanDetailVo> doorDetail(@RequestBody TrainPlan trainPlan){
        return R.ok(trainPlanService.detail(trainPlan));
    }
    /**
     * 训练计划-填写
     */
    @PostMapping("/trainPlanFillIn")
    public R FillIn(@RequestBody TrainPlanFillInPo trainPlanFillInPo){
        return R.ok(trainPlanService.FillIn(trainPlanFillInPo));
    }

//    /**
//     * 训练计划-填写-活动安排-模板下载
//     */
//    @PostMapping("/trainPlanFillIn/activity/download")
//    public R activityDownload(HttpServletResponse response){
//        return R.ok();
//    }
    /**
     * 训练计划-填写-活动安排-模板数据解析
     */
    @PostMapping("/trainPlanFillIn/activity/parse")
    public R<List<TrainPlanActivity>> activityParse(@RequestParam("file") MultipartFile file){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(trainPlanService.activityParse(file));
    }

    /**
     * 训练计划-填写-活动安排-批量添加
     */
    @PostMapping("/trainPlanFillIn/activity/batchAdd")
    public R activityBatchAdd(List<TrainPlanActivity> trainPlanActivityList){
        return R.ok(trainPlanService.activityBatchAdd(trainPlanActivityList));
    }

//    /**
//     * 训练计划-填写-教学安排-模板下载
//     */
//    @PostMapping("/trainPlanFillIn/teach/download")
//    public R teachDownload(HttpServletResponse response){
//        return R.ok();
//    }
    /**
     * 训练计划-填写-教学安排-模板数据解析
     */
    @PostMapping("/trainPlanFillIn/teach/parse")
    public R<List<TrainPlanTeach>> teachParse(@RequestParam("file") MultipartFile file){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(trainPlanService.teachParse(file));
    }

    /**
     * 训练计划-填写-教学安排-批量添加
     */
    @PostMapping("/trainPlanFillIn/teach/batchAdd")
    public R teachBatchAdd(List<TrainPlanTeach> trainPlanTeachList){
        return R.ok(trainPlanService.teachBatchAdd(trainPlanTeachList));
    }

//    /**
//     * 训练计划-填写-职业教育工作计划-模板下载
//     */
//    @PostMapping("/trainPlanFillIn/education/download")
//    public R educationDownload(HttpServletResponse response){
//        return R.ok();
//    }
    /**
     * 训练计划-填写-职业教育工作计划-模板数据解析
     */
    @PostMapping("/trainPlanFillIn/education/parse")
    public R<List<TrainPlanEducation>> educationParse(@RequestParam("file") MultipartFile file){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(trainPlanService.educationParse(file));
    }

    /**
     * 训练计划-填写-职业教育工作计划-批量添加
     */
    @PostMapping("/trainPlanFillIn/education/batchAdd")
    public R educationBatchAdd(List<TrainPlanEducation> trainPlanEducationList){
        return R.ok(trainPlanService.educationBatchAdd(trainPlanEducationList));
    }

//    /**
//     * 训练计划-填写-阶段计划-模板下载
//     */
//    @PostMapping("/trainPlanFillIn/stage/download")
//    public R stageDownload(HttpServletResponse response){
//        return R.ok();
//    }
    /**
     * 训练计划-填写-阶段计划-模板数据解析
     */
    @PostMapping("/trainPlanFillIn/stage/parse")
    public R<List<TrainPlanStage>> stageParse(@RequestParam("file") MultipartFile file){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(trainPlanService.stageParse(file));
    }

    /**
     * 训练计划-填写-阶段计划-批量添加
     */
    @PostMapping("/trainPlanFillIn/stage/batchAdd")
    public R stageBatchAdd(List<TrainPlanStage> trainPlanStageList){
        return R.ok(trainPlanService.stageBatchAdd(trainPlanStageList));
    }

    /**
     * 训练计划-填写-其他（除年）-模板数据解析
     */
    @PostMapping("/trainPlanFillIn/Item/parse")
    public R<List<TrainPlanItem>> itemParse(@RequestParam("file") MultipartFile file){
        // 获取用户信息
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(trainPlanService.itemParse(file));
    }

    /**
     * 训练计划-填写-其他（除年）-批量添加
     */
    @PostMapping("/trainPlanFillIn/Item/batchAdd")
    public R itemBatchAdd(List<TrainPlanItem> trainPlanStageList){
        return R.ok(trainPlanService.itemBatchAdd(trainPlanStageList));
    }

    /**
     * 训练计划-填写-模板下载
     */
    @PostMapping("/trainPlanFillIn/download")
    public R stageDownload(@RequestBody TrainPlanFillInDownloadPo trainPlanFillInDownloadPo, HttpServletResponse response){
        return R.ok(trainPlanService.stageDownload(trainPlanFillInDownloadPo,response));
    }
    /**
     * 工作台-内容较审&训练档案待办
     */
    @PostMapping("/reviewAndTraining")
    public R reviewAndTraining(@RequestBody ReviewAndTrainingPo reviewAndTrainingPo){
        return R.ok(trainPlanService.reviewAndTraining(reviewAndTrainingPo));
    }
    /**
     * 统计分析-训练档案-训练计划统计
     */
    @PostMapping("/trainingArchives/planStatistics")
    public R trainingArchivesPlanStatistics(){
        return R.ok(trainPlanService.trainingArchivesPlanStatistics());
    }

    /**
     * 训练计划导入
     * @return
     */
    @PostMapping("/planExcel")
    public R planExcel(@RequestPart("file") MultipartFile file){
        return R.ok(trainPlanService.planExcel(file));
    }

}

